package com.aeoj.clientmanagement.domain.room.vo;

import com.aeoj.clientmanagement.domain.room.Room;
import com.aeoj.clientmanagement.domain.user.vo.SysUserVO;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.Date;

/**
 * author: ZSM
 * time: 2025-04-21 13:14
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class RoomVO {
    /**
     * 房间ID
     */
    private Long id;

    /**
     * 房间名称
     */
    private String name;

    /**
     * 房间头像URL
     */
    private String avatar;

    /**
     * 房间描述
     */
    private String description;

    /**
     * 房间标签，逗号分隔的字符串
     */
    private String tags;

    /**
     * 房间人数限制
     */
    private Integer maxMembers;

    /**
     * 现有人数
     */
    private Integer count;

    /**
     * 房间类型：0-公开，1-加密，2-私人
     */
    private Integer type;

    /**
     * 过期时间
     */
    private Date expireTime;

    /**
     * 创建者用户ID
     */
    private Long createBy;

    private SysUserVO createUser;

    /**
     * 创建时间
     */
    private Date createTime;

    public static RoomVO toRoomVO(Room room) {
        if (room == null) {
            return null;
        }
        return RoomVO.builder()
                .id(room.getId())
                .name(room.getName())
                .avatar(room.getAvatar())
                .description(room.getDescription())
                .tags(room.getTags())
                .maxMembers(room.getMaxMembers())
                .type(room.getType())
                .expireTime(room.getExpireTime())
                .createBy(room.getCreateBy())
                .createTime(room.getCreateTime())
                .build();
    }

    public Room toRoom() {
        return Room.builder()
                .id(this.getId())
                .name(this.getName())
                .avatar(this.getAvatar())
                .description(this.getDescription())
                .tags(this.getTags())
                .maxMembers(this.getMaxMembers())
                .type(this.getType())
                .expireTime(this.getExpireTime())
                .createBy(this.getCreateBy())
                .createTime(this.getCreateTime())
                .build();
    }
}
